package com.finstate.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.finstate.dao.RateDao;
import com.finstate.domain.Rate;

@Repository
public class RateDaoImpl implements RateDao {

	@Autowired
	private SessionFactory session;
	
	@SuppressWarnings("unchecked")
	public List<Rate> getRates() {
		List<Rate> rates = session.getCurrentSession().createQuery("from Rate").list();
		return rates;
	}

	public void deleteRate(Long rateId) {
		Rate rate = (Rate) session.getCurrentSession().get(Rate.class, rateId);
		if (null != rate) {
			session.getCurrentSession().delete(rate);
		}
	}
	
	public Rate getRate(Long rateId) {
		return (Rate)session.getCurrentSession().get(Rate.class, rateId);
	}
	
	public void addRate(Rate rate) {
		session.getCurrentSession().save(rate);
	}



}
